package com.wl2o2o.lanqiao.xzfourteen;
/** 
* @author : WLei224
* @date ：2023年4月2日 上午11:35:58 
* 
*/
//1:无需package
//2: 类名必须Main, 不可修改

public class zhouqichuan {
 public static void main(String[] args) {
     String a =  "helloworld";
     String s =  a + a;
     System.out.println(cycle(s));
     System.out.println(cycle1(s));

 }

 //判断是否为周期串
 public static int cycle(String s){
     char[] ch = s.toCharArray();
     int T;
     for(T = 1; T < ch.length; T++){
         if(ch.length % T ==0){
             boolean flag = true;
             for(int start = T;start < ch.length; start++){
                 if(ch[start] != ch[start % T]){
                     flag = false;
                     break;
                 }
             }
             if(flag) break;
         }
     }
     return T;
 }

 //pos标记法
 public static int cycle1(String s){
	// bug  TODO Auto-generated method stub
	 int pos;
     for(pos = 1; pos < s.length(); pos++){
         if(s.length()/2 % pos != 0)continue;
         String ans = s.substring(pos,pos + s.length()/2);
         if(ans.equals(s))break;
     }
     return pos;
 }

}